package o;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.audio.AudioProcessor;
import com.google.android.exoplayer2.audio.AudioProcessor.UnhandledFormatException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

public final class acp implements AudioProcessor {
    private boolean ʻ;
    private ByteBuffer ʼ = ˏ;
    @Nullable
    private int[] ʽ;
    @Nullable
    private int[] ˊ;
    private int ˋ = -1;
    private int ˎ = -1;
    private boolean ॱ;
    private ByteBuffer ᐝ = ˏ;

    public void ˏ(@Nullable int[] iArr) {
        this.ˊ = iArr;
    }

    public boolean ˋ(int i, int i2, int i3) throws UnhandledFormatException {
        boolean z = !Arrays.equals(this.ˊ, this.ʽ);
        this.ʽ = this.ˊ;
        if (this.ʽ == null) {
            this.ॱ = false;
            return z;
        } else if (i3 != 2) {
            throw new UnhandledFormatException(i, i2, i3);
        } else if (!z && this.ˎ == i && this.ˋ == i2) {
            return false;
        } else {
            this.ˎ = i;
            this.ˋ = i2;
            if (i2 != this.ʽ.length) {
                z = true;
            } else {
                z = false;
            }
            this.ॱ = z;
            int i4 = 0;
            while (i4 < this.ʽ.length) {
                int i5 = this.ʽ[i4];
                if (i5 >= i2) {
                    throw new UnhandledFormatException(i, i2, i3);
                }
                this.ॱ = (i5 != i4 ? 1 : 0) | this.ॱ;
                i4++;
            }
            return true;
        }
    }

    public boolean ˏ() {
        return this.ॱ;
    }

    public int ˋ() {
        return this.ʽ == null ? this.ˋ : this.ʽ.length;
    }

    public int ˊ() {
        return 2;
    }

    public int ˎ() {
        return this.ˎ;
    }

    public void ˎ(ByteBuffer byteBuffer) {
        amm.ˏ(this.ʽ != null);
        int position = byteBuffer.position();
        int limit = byteBuffer.limit();
        int length = (((limit - position) / (this.ˋ * 2)) * this.ʽ.length) * 2;
        if (this.ᐝ.capacity() < length) {
            this.ᐝ = ByteBuffer.allocateDirect(length).order(ByteOrder.nativeOrder());
            length = position;
        } else {
            this.ᐝ.clear();
            length = position;
        }
        while (length < limit) {
            for (int i : this.ʽ) {
                this.ᐝ.putShort(byteBuffer.getShort((i * 2) + length));
            }
            length = (this.ˋ * 2) + length;
        }
        byteBuffer.position(limit);
        this.ᐝ.flip();
        this.ʼ = this.ᐝ;
    }

    public void ॱ() {
        this.ʻ = true;
    }

    public ByteBuffer ʽ() {
        ByteBuffer byteBuffer = this.ʼ;
        this.ʼ = ˏ;
        return byteBuffer;
    }

    public boolean ʻ() {
        return this.ʻ && this.ʼ == ˏ;
    }

    public void ʼ() {
        this.ʼ = ˏ;
        this.ʻ = false;
    }

    public void ᐝ() {
        ʼ();
        this.ᐝ = ˏ;
        this.ˋ = -1;
        this.ˎ = -1;
        this.ʽ = null;
        this.ˊ = null;
        this.ॱ = false;
    }
}
